var STATUS;
var wait = 60;
var cce;
var sendcode = "/index.php/common/sendCode";
var editPassword = "/index.php/member/password";
if (typeof window.IS_MOBILE !== "undefined") {
    sendcode = "/mobile/Common/sendCode";
    editPassword = "/mobile/member/editPassword"
}
$(function() {
    $(".control .button").hover(function() {
        $(this).toggleClass("button_hover")
    });
    if (STATUS == 1) {
        showMsg("抱歉。为安全起见，您的密码在初次登录或后台重置后，需重新设定。")
    } else {
        if (STATUS == 2) {
            showMsg("抱歉。您的密码已超过使用期限。为安全起见，请重新设定。")
        }
    }
    $("#get_code").click(function() {
        $.get(sendcode, {
            type: 0,
            template: "unbind"
        },
        function(a) {
            if (a.success) {
                dialog.alert("消息", "验证码已发送，请注意查收!"+a.code);
                wait = 60;
                clearTimeout(cce);
                time_2($("#get_code"))
            } else {
                dialog.error("消息", "验证码发送错误，请重新发送或联系客服!")
            }
        },'json')
    })
});
function time_2(a) {
    if (wait == 0) {
        a.removeAttr("disabled");
        a.val("点击获取");
        wait = 60
    } else {
        a.attr("disabled", "disabled");
        a.val("(" + wait + ")秒后重新获取验证码");
        wait--;
        cce = setTimeout(function() {
            time_2(a)
        },
        1000)
    }
}
function check(d, c, b) {
    for (var e = 0, a = c.length - b; e <= a; e++) {
        if (d.indexOf(c.substr(e, b)) != -1) {
            return false
        }
    }
    return true
}
function testPassword(a) {
    if (!check(a, "123456789", 4)) {
        return true
    }
    if (!check(a, "987654321", 4)) {
        return true
    }
    if (/^[a-z]+$/.test(a) || /^[0-9]+$/.test(a)) {
        return true
    }
    return false
}
function showMsg(a) {
    if (parent && parent != window && parent.showMsg) {
        parent.showMsg(a)
    } else {
        alert(a)
    }
}
function changePassword() {
    var a = $("#oldPassword").val();
    var c = $("#password").val();
    var b = $("#ckPassword").val();
    var d = $("#code").val();
    if (a.length == 0) {
        showMsg("请输入原始密码！");
        $("#oldPassword").focus();
        return
    }
	if(c.length==0){
		   showMsg("请输入新密码");
        
        return
	}
    if (c != b) {
        showMsg("新设密码 和 新设密码确认 不一样！(确认大小写是否相同)");
        $("#ckPassword").focus();
        return
    }
	if(d.length==0){
		   showMsg("请输入验证码");
        
        return
	}
    if (!confirm("是否确定要修改密码？")) {
        return
    }
    $.post(editPassword, {
        oldPassword: a,
        password: c,
        code: d
    },
    function(f) {
        if (f.success) {
            showMsg("密码修改成功。");
            var e = LIBS.getUrlParam("url");
            if (e) {
                location.href = e
            } else {
                history.back()
            }
        } else {
            showMsg(f.message);
            $("#oldPassword").focus()
        }
    },'json')
};